import Container from '@/components/src/container';
import AsideNav from '@/components/src/aside_nav/jsx/aside_nav.jsx';
import Header from '@/components/src/header';

import Center from '@/components/src/center';
import Footer from '@/components/src/footer';
import $DZ from 'base';
import API from 'api';

import React from "react";


import 'antd/dist/antd.css';
import { Layout, Menu, Breadcrumb, Icon } from 'antd';
const { SubMenu } = Menu;
const { Content, Sider } = Layout;



const DZonline = process.env.NODE_ENV == "production";

class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            login:true
        }
       
    }
    componentWillMount() {
        this.getLogin();
    }
    componentDidMount() {
       
    }
    componentWillReceiveProps(nextProps) {
        if(this.props.location.pathname != "/login") {
           this.getState()
        }
    }

    componentDidUpdate() {
    }

    componentWillUnmount() {

    }
    getLogin=()=>{
        this.props.dispatch(Actions.login.requestGetData())
       
    }
    getState=()=>{
        this.props.dispatch(Actions.login.requestGetData())
        let {loginState}=this.props.loginState.rescode
        if(!loginState){
            location.hash="login"
         }
    }
    render() {
       let login = this.props.loginState.rescode==0?true:false
        return (
            <Layout  className={login?"":"nobg"}>
                {login?<Header/>:""}
                <Layout   className={login?"":"nobg"}>
                    {
                        login
                        ?<Sider width={200} style={{ background: '#fff' }}>
                          <AsideNav></AsideNav>
                         </Sider>
                        :""
                    }
                    {
                        login
                         ?<Layout style={{ padding: '0 24px 24px' }}>
                            <Center>
                            {this.props.children}
                            </Center>
                        </Layout>
                        :this.props.children
                    }
                   
                </Layout>
            </Layout>
        )
    }
}

export default  Connect(
    state => {
        return {
            loginState: state.loginReducers,
        }
    },
)(Main);